﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class appleader_projects_end : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            MasApp.BLL.Check.CheckLogin();
            //判断任务是否全部完成，没有则返回
            if (Request.QueryString[0] != null)
            {
                int projectid = int.Parse(Request.QueryString[0].ToString());
                if (!MasApp.BLL.Search.MissionAllFinish(projectid))
                {
                    Label lb = new Label();
                    lb.Text = "尚有项目任务未完成（或者尚未提交），不能生成结果！";
                    lb.ForeColor = System.Drawing.Color.Red;
                    lb.Font.Size = FontUnit.Larger;
                    form1.Controls.AddAt(1, lb);
                    HyperLink hy = new HyperLink();
                    hy.NavigateUrl = "list.aspx";
                    hy.Text = "<br />返回";
                    form1.Controls.Add(hy);
                }

                //直接赋权是另外判断是否完成评权任务
                if (MasApp.BLL.Search.SearchProjectWeightType(projectid).Equals("直接赋权"))
                {
                    DataTable dt = MasApp.BLL.Search.WeightValue(projectid);
                    //直接赋权是判断准则评权是否完成
                    float allrulevalue = 0;
                    foreach (DataRow dr in dt.Rows)
                    {
                        if (dr[1].ToString().Equals("准则"))
                        {
                            allrulevalue += Convert.ToSingle(dr[2].ToString());
                            //直接赋权下判断各指标评权是否完成
                            float allindivalue = 0;
                            foreach (DataRow dr1 in dt.Rows)
                            {
                                if (dr1[1].ToString().Equals("指标"))
                                {
                                    //Convert.ToInt32(dr1[0].ToString()) 是指标ID
                                    if (MasApp.BLL.Search.RuleID(Convert.ToInt32(dr1[0].ToString())) == int.Parse(dr[0].ToString()))
                                    {
                                        allindivalue += Convert.ToSingle(dr1[2].ToString());
                                    }
                                }
                            }
                            if ((allindivalue - 1F) > 0.0000001F)
                            {
                                Label lb = new Label();
                                lb.Text = "直接赋权：准则赋权任务未完成，不能生成结果！";
                                lb.ForeColor = System.Drawing.Color.Red;
                                lb.Font.Size = FontUnit.Larger;
                                form1.Controls.AddAt(1, lb);
                                HyperLink hy = new HyperLink();
                                hy.NavigateUrl = "list.aspx";
                                hy.Text = "<br />返回";
                                form1.Controls.Add(hy);
                            }
                        }
                    }
                    if ((allrulevalue - 1F) > 0.0000001F)
                    {
                        Label lb = new Label();
                        lb.Text = "直接赋权：指标赋权任务未完成，不能生成结果！";
                        lb.ForeColor = System.Drawing.Color.Red;
                        lb.Font.Size = FontUnit.Larger;
                        form1.Controls.AddAt(1, lb);
                        HyperLink hy = new HyperLink();
                        hy.NavigateUrl = "list.aspx";
                        hy.Text = "<br />返回";
                        form1.Controls.Add(hy);
                    }
                }
            }
            else
            {
                MasApp.BLL.ResponseHelper.alert("非法链接！", "list.aspx");
            }
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (Request.QueryString[0] != null)
        {            
            int projectid = int.Parse(Request.QueryString[0].ToString());
            if (MasApp.BLL.Update.UpdateProjectState(projectid, "有效的") > 0)
            {
                MasApp.BLL.ResponseHelper.alert("成功结束项目，可以查看项目的评估结果了！", "../result/list.aspx");
            }
            else
            {
                MasApp.BLL.ResponseHelper.alert("操作失败", "endlist.aspx");
            }
        }
        else
        {
            MasApp.BLL.ResponseHelper.alert("非法链接", "endlist.aspx");
        }
    }
}
